﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>权限</title>
    <link href="~/EasyUI/themes/icon.css" rel="stylesheet" />
    <link href="~/EasyUI/themes/default/easyui.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="~/EasyUI/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="~/Scripts/jquery.validate.min.js"></script>
    @* 自动为表单 添加验证功能的js文件 -- 微软提供
        <script type="text/javascript" src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
    *@
    <script type="text/javascript" src="~/Scripts/jquery.msgProcess.js"></script>

    <script type="text/javascript">
        $(function () {
            $('#editWindow').window('close');
            $("#tbList").datagrid({
                width: 'auto',
                height: 'auto',
                fitColumns: true,
                striped: true,
                singleSelect: true,
                url: '/admin/user/index',
                //queryParams:{},
                loadMsg: '数据加载中请稍后……',
                pagination: true,//启用分页，默认每页10行
                rownumbers: true,//显示页码，默认 提供 10 - 50 的页容量选择下拉框
                pageSize: 10,//设置 页容量为 5
                pageList: [5, 10, 20],//设置 页容量下拉框
                columns: [[

                    { field: 'id', title: 'ID', width: 100 },
                    { field: 'loginname', title: '登录名', width: 100 },
                    { field: 'username', title: '姓名', width: 100 },
                    {
                        field: 'gender', title: '性别', width: 100, align: "center",
                        formatter: function (value) {
                            if(value)
                                return "男"
                            else
                                return "女"
                        }
                    },
                    { field: 'Rolename', title: '角色', width: 100 },
                    { field: 'downNum', title: '可下次数', width: 100 }
                ]],
                toolbar: [{
                    iconCls: 'icon-add',
                    text: "新增",
                    handler: addRow
                }, '-', {
                    iconCls: 'icon-remove',
                    text: "删除",
                    handler: removeRow
                }, '-', {
                    iconCls: 'icon-edit',
                    text: "编辑",
                    handler: editRow
                }],
                onSelect: function (rowI, rowD) {
                    selectedRowIndex = rowI;//将选中行的下标 设置给全局变量
                },
                onDblClickRow: function () {
                    editRow();
                }
            });

            var loginName = '@ViewBag.loginname';
            debugger;
            if (loginName == "admin") {
                //加载店铺
                $.ajax({
                    type: "POST",
                    url: "/admin/Shop/DataList",
                    data: { page: 1, rows: 1000 },
                    dataType: "json",
                    success: function (data) {
                        // $('#shops').empty();   //清空shops里面的所有内容
                        var html = '';
                        $.each(data.rows, function (commentIndex, comment) {
                            html += '<option value="' + comment['ID'] + '"> ' + comment['ShopName'] + '</option>';
                        });
                        $('#shops').append(html);
                    }
                });
            }
            else {
                $("#spanshop").hide();
            }
           

            $("#btnserch").click(function () {
                $('#tbList').datagrid('load', {
                    keyword: $('#txtkey').val(),
                    Shopid: $('#shops').val(),
                });
            })

        })

        //选中行的下标
        var selectedRowIndex = -1;

        //编辑按钮方法
        function editRow() {
            //获取选中行里的数据！
            var rowData = $("#tbList").datagrid("getSelected");
            if (rowData) {
                $('#editWindow').window('open');

                $.get("/admin/user/editrole?id=" + rowData.id + "&rid=" + rowData.Rid + "&Shopid=" + rowData.Shopid + "&t=" + new Date().getTime(), null, function (jsonObj) {
                    if (jsonObj.Status)
                        $.procAjaxData(jsonObj);
                    else
                        $("#editWindow").html(jsonObj);

                });
            }
        }

        //新增按钮方法
        function addRow() {
            $('#editWindow').window('open');
            //$("#editWindow").load("/admin/sys/addpermission/");
            $.get("/admin/user/addrole/?t=" + new Date().getTime(), null, function (jsonObj) {
                if (jsonObj.Status)
                    $.procAjaxData(jsonObj);
                else
                    $("#editWindow").html(jsonObj);

            });
        }

        //删除方法
        function removeRow() {
            if (!confirm("确认要删除？")) {
                return false;
            }
            //获取选中行里的数据！
            var rowData = $("#tbList").datagrid("getSelected");
            if (rowData) {
                $.post("/admin/user/delrole", "id=" + rowData.id, function (jsonObj) {
                    $.procAjaxData(jsonObj, function () {
                        $("#tbList").datagrid("reload");//删除成功后 刷新页面
                    });
                }, "JSON");
            }
        }
        //查看子权限
        function viewSon() {
            var rowData = $("#tbList").datagrid("getSelected");
            window.location = "/admin/sys/PermissionSon?id=" + rowData.Id;
        }
        // submit the form
        //$('#ff').submit();
    </script>
</head>
<body>
    <div style=" margin:15px 0px 20px 50px">
        姓名：<input id="txtkey" type="text" /> &nbsp; &nbsp;
           <span id="spanshop">
               所属店铺： <select id="shops">
                   <option value="0"> 请选择</option>
               </select>
               &nbsp; &nbsp;
           </span>
        <input id="btnserch" type="button" value="搜索" />

    </div>

    <table id="tbList" style="width:400px;height:250px"></table>

    <div id="editWindow" class="easyui-window" title="编辑账户" style="width:600px;height:400px;"
         data-options="iconCls:'icon-save',modal:true">

    </div>
</body>
</html>
